﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gueei.Gallery.Core.DisplayProfiles;
using Gueei.Gallery.Core.Entities;

namespace Gueei.Gallery.Core.Repositories
{
	public class DefaultDisplayProfileRepository : IDisplayProfileRepository
	{
		private static readonly DisplayProfileBase _defaultDisplayProfile = new DisplayProfile() {
			MaxWidth = 800,
			MaxHeight = 800,
			MaintainRatio = true,
			Name = DefaultProfileName.Defaultsize,
			ResizeIfSmaller = false,
			NeedCache = true
		};

		private static readonly DisplayProfileBase _fullSizeDisplayProfile = new DisplayProfileBase() {
			Name = DefaultProfileName.Fullsize,
			NeedCache = false
		};

		private static readonly DisplayProfileBase _thumbnailDisplayProfile = new DisplayProfile()
		                                                                      	{
																					Name = DefaultProfileName.Thumbsize,
		                                                                      		MaxWidth = 100,
		                                                                      		MaxHeight = 100,
		                                                                      		MaintainRatio = true,
		                                                                      		ResizeIfSmaller = false,
		                                                                      		NeedCache = true
		                                                                      	};

		private HashSet<DisplayProfileBase> _profiles = InitProfiles();

		private static HashSet<DisplayProfileBase> InitProfiles()
		{
			var profiles = new HashSet<DisplayProfileBase> {_defaultDisplayProfile, _fullSizeDisplayProfile, _thumbnailDisplayProfile};
			return profiles;
		}

		public DisplayProfileBase DefaultDisplayProfile
		{
			get { return _defaultDisplayProfile; }
		}

		public DisplayProfileBase GetDisplayProfileByName(string name)
		{
			var profile = _profiles.FirstOrDefault(p => p.Name == name.ToLower());
			return profile ?? _defaultDisplayProfile;
		}

		public DisplayProfileBase GetDisplayProfileById(Guid id)
		{
			throw new NotImplementedException();
		}


		public DisplayProfileBase FullSizeDisplayProfile
		{
			get { return _fullSizeDisplayProfile; }
		}


		public DisplayProfileBase ThumbnailDisplayProfile
		{
			get { return _thumbnailDisplayProfile; }
		}
	}
}
